package com.hyz.listener;

import com.alibaba.fastjson.JSON;
import com.hyz.pojo.assetSecondment.AssetSecondment;
import com.hyz.service.AssetSecondmentService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author HGD
 * @date 2022/10/4 23:50
 */
@Component
public class AssetSecondmentListener {
    @Autowired
    private AssetSecondmentService service;

    /**
     * 新增数据
     *
     * @param message json字符串
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "assetSecondment.queue"),
            exchange = @Exchange(name = "assetApplicant", type = ExchangeTypes.DIRECT),
            key = {"insertAssetSecondment"}
    ))
    public void insertAssetSecondment(String message) {
        AssetSecondment assetSecondment = JSON.parseObject(message, AssetSecondment.class);
        service.save(assetSecondment);
    }
}
